package com.irdstudio.efp.flow.service;

import com.irdstudio.efp.flow.service.facade.*;
import com.irdstudio.efp.flow.service.vo.InstFlowEventVO;
import com.irdstudio.efp.flow.service.vo.InstFlowParamVO;
import com.irdstudio.efp.flow.service.vo.InstFlowProcessVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @param ${params}
 * @author xieziwei
 * @version 0.1
 * @return ${return}
 * @date 2019/11/21 15:36
 */
@Service
public class FlowRepulseUtil {

    private static Logger logger = LoggerFactory.getLogger(FlowRepulseUtil.class);

    @Autowired
    @Qualifier("instFlowEventService")
    private InstFlowEventService instFlowEventService;

    @Autowired
    @Qualifier("instFlowInfoService")
    private InstFlowInfoService instFlowInfoService;

    @Autowired
    @Qualifier("instFlowParamService")
    private InstFlowParamService instFlowParamService;

    @Autowired
    @Qualifier("instFlowProcessService")
    private InstFlowProcessService instFlowProcessService;

    @Autowired
    @Qualifier("instFlowTaskService")
    private InstFlowTaskService instFlowTaskService;

    public void cleanRepulseAllInfo(String bizSerno){
        logger.info("开始清除上次打回信息......");
        int num = 0;
        List<InstFlowProcessVO> VOS = instFlowProcessService.queryAllByBizSerno(bizSerno);
        for (InstFlowProcessVO item: VOS) {
            num = instFlowTaskService.deleteByPk(item.getInstNodeId());
            if(num == 0){
                return;
            }
        }

        InstFlowEventVO instFlowEventVO = new InstFlowEventVO();
        instFlowEventVO.setBizSerno(bizSerno);
        num = instFlowEventService.deleteByPk(instFlowEventVO);
        if(num == 0){
            return;
        }
        num = instFlowInfoService.deleteByPk(bizSerno);
        if(num == 0){
            return;
        }
        InstFlowParamVO instFlowParamVO = new InstFlowParamVO();
        instFlowParamVO.setBizSerno(bizSerno);
        num = instFlowParamService.deleteByPk(instFlowParamVO);
        if(num == 0){
            return;
        }
        InstFlowProcessVO instFlowProcessVO = new InstFlowProcessVO();
        instFlowProcessVO.setBizSerno(bizSerno);
        num  = instFlowProcessService.deleteByPk(instFlowProcessVO);
        if(num == 0){
            return;
        }
        logger.info("结束清除上次打回信息......");

    }
}
